package com.ynny.chapter05;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageInfo;
import com.github.yulichang.query.MPJLambdaQueryWrapper;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.ynny.chapter05.entity.Address;
import com.ynny.chapter05.entity.Emp;
import com.ynny.chapter05.entity.User;
import com.ynny.chapter05.entity.UserDTO;
import com.ynny.chapter05.mapper.AddressMapper;
import com.ynny.chapter05.mapper.UserMapper;
import com.ynny.chapter05.service.UserService;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;



@SpringBootTest
class Chapter05ApplicationTests {

  


    @Test
    public void testConsumer(){


        List<Emp> emps = new ArrayList<>();
        Emp e1 = new Emp(1, "张三", 8000);
        Emp e2 = new Emp(2, "李四", 9000);
        Emp e3 = new Emp(3, "王五", 10000);
        Emp e4 = new Emp(4, "赵六", 11000);
        Emp e5 = new Emp(5, "钱七", 12000);
        emps.add(e1);
        emps.add(e2);
        emps.add(e3);
        emps.add(e4);
        emps.add(e5);

//        ArrayList<Emp> list = new ArrayList<>();
//        for (Emp emp : emps) {
//            if (emp.getSalary() > 10000){
//                list.add(emp);
//            }
//        }
//        System.out.println(list);


        //接口不允许实例化
        //手动 重写接口的方法
        //lambda表达式
//        emps.forEach(emp -> {
//            if (emp.getSalary() > 10000){
//                list.add(emp);
//            }
//        });

        System.out.println(emps);

        //1.创建一个Strea流

        //流水线一样 里面的一个个数据进行处理
        Stream<Emp> stream = emps.stream();
        //2.对流中的数据进行过滤
        List<Emp> newEmps = stream.filter(new Predicate<Emp>() {
            @Override
            public boolean test(Emp emp) {
                //为真 满足条件 就留下
                if (emp.getSalary() > 10000) {
                    return true;
                }
                return false;
            }
        }).collect(Collectors.toList());//3.终结


        System.out.println(newEmps);


    }

    @Test
    public void testConsumer02(){


        List<Emp> emps = new ArrayList<>();
        Emp e1 = new Emp(1, "张三", 8000);
        Emp e2 = new Emp(2, "李四", 9000);
        Emp e3 = new Emp(3, "王五", 10000);
        Emp e4 = new Emp(4, "赵六", 11000);
        Emp e5 = new Emp(5, "钱七", 12000);
        emps.add(e1);
        emps.add(e2);
        emps.add(e3);
        emps.add(e4);
        emps.add(e5);

        System.out.println(emps);



        //1.创建一个Stream流

        //流水线一样 里面的一个个数据进行处理
        List<Emp> newEmps = emps
                .stream()


                .filter(emp -> emp.getSalary() > 10000)




                .collect(Collectors.toList());//3.终结
//
//
//
//
        System.out.println(newEmps);


        //map

        List<Integer> res = emps.stream()
                .map(emp -> emp.getId())
                .sorted((o1, o2) -> o2 - o1)
                .collect(Collectors.toList());


        System.out.println(res);

    }


}
